package com.goods.controller.business;


import com.github.pagehelper.Page;
import com.goods.common.model.business.*;
import com.goods.common.response.ResponseBean;
import com.goods.common.vo.business.*;
import com.goods.common.vo.system.PageVO;
import com.goods.service.businessService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiParam;
import org.apache.tomcat.jni.LibraryNotFoundError;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;


@Api(tags = "系统模块-部门相关接口")
@RestController
@RequestMapping("/business")
public class businessController {
    @Autowired
    private businessService businessService;

    //business/inStock/findInStockList?pageNum=1&pageSize=10&status=0
    @ApiParam("入库记录分页")
    @GetMapping("/inStock/findInStockList")
    public ResponseBean findInStockList(@RequestParam(value = "pageNum",defaultValue = "1") Integer pageNum,
                                        @RequestParam(value = "pageSize") Integer pageSize,
                                        @RequestParam(value = "status",defaultValue = "0") Integer status,
                                        InStockVO inStockVO){
        PageVO<InStockVO> inStockVOPageVO=businessService.findInStockList(pageNum,pageSize,inStockVO);
        System.out.println(inStockVO);
        return ResponseBean.success(inStockVOPageVO);
    }
    //business/supplier/findSupplierList?pageNum=1&pageSize=10&name=
   @ApiParam("物质来源分页查询")
   @GetMapping("/supplier/findSupplierList")
    public ResponseBean findProductList(@RequestParam(value = "pageNum",defaultValue = "1") Integer pageNum,
                                        @RequestParam(value = "pageSize") Integer pageSize,
                                        SupplierVO supplierVO){
      PageVO<SupplierVO>  supplierVOPageVO = businessService.baseTrademark(pageNum,pageSize,supplierVO);
     return ResponseBean.success(supplierVOPageVO);
   }
    //business/productCategory/categoryTree?pageNum=1&pageSize=5
   @ApiParam("物质类别分页查询")
   @GetMapping("productCategory/categoryTree")
    public ResponseBean categoryTree(@RequestParam(value = "pageNum",defaultValue = "1") Integer pageNum,
                                        @RequestParam(value = "pageSize",defaultValue = "5") Integer pageSize){
      PageVO<ProductCategoryTreeNodeVO> productCategoryVOPageVO=  businessService.categoryTree(pageNum,pageSize);
       return ResponseBean.success(productCategoryVOPageVO);
   }

   ///business/supplier/edit/23
    @ApiParam("物资来源去修改（回显）")
    @GetMapping("/supplier/edit/{id}")
      public ResponseBean supplierEdit(@PathVariable Integer id){
        Supplier supplier= businessService.supplierEdit(id);
        return ResponseBean.success(supplier);
      }
      ///business/supplier/update/25
      @ApiParam("物资来源去修改（保存数据）")
      @PutMapping("/supplier/update/{id}")
      public ResponseBean supplierUpdate(@PathVariable Integer id,@RequestBody Supplier supplier){
          businessService.supplierUpdate(supplier);
          return ResponseBean.success();
      }

      @ApiParam("物资来源添加")
      @PostMapping("/supplier/add")
      public ResponseBean supplierAdd(@RequestBody Supplier Supplier){
          ///business/supplier/add
          businessService.supplierAdd(Supplier);
          return ResponseBean.success();
      }
    ///business/supplier/delete/23
      @ApiParam("物资来源删除")
      @DeleteMapping("/supplier/delete/{id}")
      public ResponseBean deleteSupplier(@PathVariable Integer id){
          businessService.deleteSupplier(id);
         return ResponseBean.success();
      }
    //business/productCategory/delete/20
    @ApiParam("物资类别删除")
    @DeleteMapping("/productCategory/delete/{id}")
    public ResponseBean productCategory(@PathVariable Integer id){
        businessService.deleteProductCategory(id);
        return ResponseBean.success();
    }
    ///business/consumer/delete/27
    @ApiParam("物资去处删除")
    @DeleteMapping("/consumer/delete/{id}")
    public ResponseBean DeleteConsumer(@PathVariable Integer id) {
        businessService.DeleteConsumer(id);
        return ResponseBean.success();
    }
    //    /business/productCategory/getParentCategoryTree
    @ApiParam("物资类别的父分类")
    @GetMapping("/productCategory/getParentCategoryTree")
    public ResponseBean getParentCategoryTree(){
            List<ProductCategoryTreeNodeVO>  productCategoryVOS =businessService.getParentCategoryTree();
            return ResponseBean.success(productCategoryVOS);
    }
    //business/productCategory/add
    @ApiParam("物资类别的添加")
    @PostMapping("/productCategory/add")
    public ResponseBean productCategory(@RequestBody ProductCategory productCategory){
        System.out.println(productCategory);
        businessService.addProductCategory(productCategory);
       return ResponseBean.success();
    }
    ///business/productCategory/edit/20
    @ApiParam("物资类别的修改(回显)")
    @GetMapping("/productCategory/edit/{id}")
    public ResponseBean productCategoryEdit(@PathVariable Integer id){
       ProductCategory productCategory= businessService.productCategoryEdit(id);
       return ResponseBean.success(productCategory);
    }
    //business/productCategory/update/23
    @ApiParam("物资类别的修改(保存修改)")
    @PutMapping("/productCategory/update/{id}")
    public ResponseBean productCategoryUpdate(@PathVariable Integer id,@RequestBody ProductCategory productCategory){
       businessService.productCategoryUpdate(id,productCategory);
        return ResponseBean.success();
    }
    ///business/consumer/findConsumerList?pageNum=1&pageSize=10&name=
    @ApiParam("物资去处")
    @GetMapping("/consumer/findConsumerList")
    public ResponseBean findConsumerList(@RequestParam(value = "pageNum",defaultValue = "1") Integer pageNum,
                                         @RequestParam(value = "pageSize",defaultValue = "10") Integer pageSize,
                                          ConsumerVO consumerVO){
        PageVO<ConsumerVO> consumerVOPageVO= businessService.findConsumerList(pageNum,pageSize,consumerVO);
     return ResponseBean.success(consumerVOPageVO);
    }
    ///business/product/findProductList?pageNum=1&pageSize=6&name=&categoryId=&supplier=&status=0
    ///business/product/findProducts?pageNum=1&pageSize=6&status=0&categorys=&name=
    @ApiParam("物资资料")
    @GetMapping("/product/findProductList")
    public ResponseBean findProductList(@RequestParam(value = "pageNum",defaultValue = "1") Integer pageNum,
                                         @RequestParam(value = "pageSize",defaultValue = "10") Integer pageSize,
                                         ProductVO productVO){
       PageVO<ProductVO> productVOPageVO= businessService.findProductList(pageNum,pageSize,productVO);
        return ResponseBean.success(productVOPageVO);
    }
    ///business/product/add
    @ApiParam("物资资料添加")
    @PostMapping("/product/add")
    public ResponseBean productAdd(@RequestBody Product product){
        System.out.println(product);
        businessService.productAdd(product);
        return ResponseBean.success();
    }



    //business/product/back/37
    @ApiParam("物资资料修改状态(回复)1--->0")
    @PutMapping("/product/back/{id}")
    public ResponseBean productBack(@PathVariable Integer id){
        businessService.productBack(id);
        return ResponseBean.success();
    }
    //product/remove/51
    @ApiParam("物资资料修改状态(添加到回收站)0--->1")
    @PutMapping("/product/remove/{id}")
    public ResponseBean productRemove(@PathVariable Integer id){
        businessService.productRemove(id);
        return ResponseBean.success();
    }
    //business/product/publish/54
    @ApiParam("物资资料修改状态(通过审核)2--->0")
    @PutMapping("/product/publish/{id}")
    public ResponseBean productPublish(@PathVariable Integer id){
        businessService.productPublish(id);
        return ResponseBean.success();
    }

    //business/product/findProducts?pageNum=1&pageSize=6&status=0
    @ApiParam("入库添加物资回显数据product")
    @GetMapping("/product/findProducts")
    public ResponseBean findProducts(@RequestParam(value = "pageNum",defaultValue = "1") Integer pageNum,
                                        @RequestParam(value = "pageSize",defaultValue = "10") Integer pageSize,
                                        ProductVO productVO){
        PageVO<ProductVO> productVOPageVO= businessService.findProductList(pageNum,pageSize,productVO);
        return ResponseBean.success(productVOPageVO);
    }
    ///business/inStock/addIntoStock
    @ApiParam("添加物资  保存数据")
    @PostMapping("/inStock/addIntoStock")
    public ResponseBean addIntoStock(@RequestBody  InStockVO inStockVO){
        businessService.addIntoStock(inStockVO);
        System.out.println(inStockVO);
        return ResponseBean.success();
    }
    ///business/consumer/edit/8
    @ApiParam("物资去处修改（回显数据）")
    @GetMapping("/consumer/edit/{id}")
    public ResponseBean consumerEdit(@PathVariable Integer id){
      Consumer consumer= businessService.consumerEdit(id);
        return ResponseBean.success(consumer);
    }
    ///business/consumer/update/15
    @ApiParam("物资去处修改（保存数据）")
    @PutMapping("/consumer/update/{id}")
    public ResponseBean consumerUpdate(@PathVariable Integer id,@RequestBody Consumer consumer){
        businessService.consumerUpdate(consumer);
        return ResponseBean.success();
    }

    ///business/outStock/findOutStockList?pageNum=1&pageSize=10&status=0
    @ApiParam("发放记录分页")
    @GetMapping("/outStock/findOutStockList")
    public ResponseBean findOutStockList(@RequestParam(value = "pageNum",defaultValue = "1") Integer pageNum,
                                        @RequestParam(value = "pageSize") Integer pageSize,
                                        @RequestParam(value = "status",defaultValue = "0") Integer status,
                                        OutStockVO outStockVO){
        PageVO<OutStockVO> outStockVOPageVO=businessService.findOutStockList(pageNum,pageSize,outStockVO);
        System.out.println(outStockVO);
        return ResponseBean.success(outStockVOPageVO);
    }
    //business/product/findProductStocks?pageSize=9&pageNum=1
    @ApiParam("物资库存分页")
    @GetMapping("/product/findProductStocks")
    public ResponseBean findProductStocks(@RequestParam(value = "pageNum",defaultValue = "1") Integer pageNum,
                                         @RequestParam(value = "pageSize") Integer pageSize,
                                         ProductStockVO productStockVO,ProductCategoryVO productCategoryVO){
        PageVO<ProductStockVO> productStockVOPageVO=businessService.findProductStocks(pageNum,pageSize,productStockVO);
        System.out.println(productStockVO);
        System.out.println(productCategoryVO);
        return ResponseBean.success(productStockVOPageVO);
    }

    ///business/health/report
    //请求方法: POST
    @ApiParam("健康打卡  保存数据")
    @PostMapping("/health/report")
    public ResponseBean healthReport(@RequestBody  Health health, HttpServletRequest request){
        String userId = request.getHeader("userId");
        System.out.println(userId);
        //health.setUserId(Long.parseLong(userId));
        System.out.println(health);
     //   businessService.healthReport(health);
        return ResponseBean.success();
    }
}

